package demo.gateway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Chen Jie
 * @email jie.chen@remarkdip.com
 * @date 2018/7/24
 */
@Component
@Slf4j
public class AccessFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
//        RequestContext requestContext = RequestContext.getCurrentContext();
//        HttpServletRequest request = requestContext.getRequest();
//
//        String accessToken = request.getParameter("accessToken");
//        if (StringUtils.isBlank(accessToken)) {
//            requestContext.setResponseStatusCode(401);
//            requestContext.setSendZuulResponse(false);
//            log.warn("accessToken is empty");
//            return null;
//        }
        return null;
    }
}
